package com.ls.uav_backend.controller;

import cn.hutool.core.util.ObjUtil;
import com.ls.uav_backend.common.BaseResponse;
import com.ls.uav_backend.common.ResultUtils;
import com.ls.uav_backend.exception.BusinessException;
import com.ls.uav_backend.exception.ErrorCode;
import com.ls.uav_backend.model.dto.PictureQueryDTO;
import com.ls.uav_backend.model.entity.Picture;
import com.ls.uav_backend.service.PictureService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 拍摄图片 控制层。
 *
 * @author <a href="https://gitee.com/Linkating">LinSkating</a>
 */
@RestController
@RequestMapping("/picture")
public class PictureController {

    @Resource
    private PictureService pictureService;

    @GetMapping("/fieldIdList")
    public BaseResponse<List<Integer>> getFieldIdList() {
        List<Integer> fieldIdList = pictureService.getFieldIdList();
        return ResultUtils.success(fieldIdList);
    }

    @GetMapping("/createTimeList")
    public BaseResponse<List<String>> getCreateTimeList() {
        List<String> createTimeList = pictureService.getCreateTimeList();
        return ResultUtils.success(createTimeList);
    }

    @PostMapping("/list/createTime")
    public BaseResponse<Map<Integer, List<String>>> getPictureListByCreateTime(@RequestBody PictureQueryDTO pictureQueryDTO) {
        Integer fieldId = pictureQueryDTO.getFieldId();
        LocalDateTime createTime = pictureQueryDTO.getCreateTime();
        if (ObjUtil.isNull(createTime)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数错误");
        }
        Map<Integer, List<String>> pictureList;
        if (fieldId != null) {
            pictureList = pictureService.getPictureList(fieldId, createTime);
        } else {
            pictureList = pictureService.getPictureList(createTime);
        }
        return ResultUtils.success(pictureList);
    }

}
